#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021-11-25 17:07
# @Author : huabao.tan
# @File : script.py
# @Software: PyCharm
import openpyxl
from founct.allFunction import *
from openpyxl import load_workbook
from openpyxl import Workbook
from openpyxl.writer.excel import ExcelWriter


def message():
    print("请先选择文件：")
    file = open_file()
    mag = int(input("要写入多少行："))
    wb = load_workbook(file)
    fun(wb, mag)
    wb.save(file)


def fun(wb, mag):
    sheetnames = wb.get_sheet_names()
    mzt = wb.get_sheet_by_name(sheetnames[0])
    mzt1 = wb.get_sheet_by_name(sheetnames[1])
    mzt2 = wb.get_sheet_by_name(sheetnames[2])
    mzt3 = wb.get_sheet_by_name(sheetnames[3])
    mzt4 = wb.get_sheet_by_name(sheetnames[4])
    mzt5 = wb.get_sheet_by_name(sheetnames[5])
    a = 1
    while True:
        a += 1
        name = c_name()
        other_name = c_name()
        card = creat_Idcard()
        edu = education()
        school_of_graduation = college()
        ranking = rank()
        dutying = duty()
        posting = post()
        politics_statused = politics_status()
        fosters = foster()
        sex = create_sex()
        birth_day = birthday(card)
        stat_word_time = randomtimes('1990-10-05', '1999-10-05', 1)[0]
        join_party_time = randomtimes('1995-10-05', '1999-10-05', 1)[0]
        second_stat_time = randomtimes('1995-10-05', '1999-10-05', 1)[0]
        graduate_time = randomtimes('1995-10-05', '2010-10-05', 1)[0]
        stat_birth = randomtimes('1970-10-05', '1990-10-05', 1)[0]
        positions = position()
        nations = nation()
        native_places = native_place()
        of_types = of_type()
        affiliation_types = affiliation_type()
        units = unit()
        specialtys = specialty()
        degrees = degree()
        learning_formats = learning_format()
        relations = relation()
        others_type = other_type()
        naures = nature()
        exchanges = exchange()
        mzt.cell(row=a, column=1, value=card)
        mzt.cell(row=a, column=2, value=name)
        mzt.cell(row=a, column=3, value=ranking)
        mzt.cell(row=a, column=4, value=positions)
        mzt.cell(row=a, column=5, value=dutying)
        mzt.cell(row=a, column=6, value=posting)
        mzt.cell(row=a, column=7, value=sex)
        mzt.cell(row=a, column=8, value=birth_day)
        mzt.cell(row=a, column=9, value=nations)
        mzt.cell(row=a, column=10, value=native_places)
        mzt.cell(row=a, column=11, value=stat_word_time)
        mzt.cell(row=a, column=12, value=join_party_time)
        mzt.cell(row=a, column=13, value=politics_statused)
        mzt.cell(row=a, column=14, value=stat_word_time)
        mzt.cell(row=a, column=15, value=second_stat_time)
        mzt.cell(row=a, column=16, value=fosters)
        mzt.cell(row=a, column=17, value=native_places)
        mzt.cell(row=a, column=18, value=native_places)
        mzt.cell(row=a, column=19, value='宇宙超级秀萝萝')
        mzt.cell(row=a, column=20, value='宇宙超级秀萝萝')
        mzt1.cell(row=a, column=1, value=card)
        mzt1.cell(row=a, column=2, value=name)
        mzt1.cell(row=a, column=3, value='临时库')
        mzt2.cell(row=a, column=1, value=card)
        mzt2.cell(row=a, column=2, value=name)
        mzt2.cell(row=a, column=3, value=units)
        mzt2.cell(row=a, column=4, value=of_types)
        mzt2.cell(row=a, column=5, value=affiliation_types)
        mzt2.cell(row=a, column=6, value='宇宙超级秀萝萝')
        mzt3.cell(row=a, column=1, value=card)
        mzt3.cell(row=a, column=2, value=name)
        mzt3.cell(row=a, column=3, value=edu)
        mzt3.cell(row=a, column=4, value=graduate_time)
        mzt3.cell(row=a, column=5, value=school_of_graduation)
        mzt3.cell(row=a, column=6, value=specialtys)
        mzt3.cell(row=a, column=7, value=degrees)
        mzt3.cell(row=a, column=8, value=learning_formats)
        mzt4.cell(row=a, column=1, value=card)
        mzt4.cell(row=a, column=2, value=name)
        mzt4.cell(row=a, column=3, value=other_name)
        mzt4.cell(row=a, column=4, value=relations)
        mzt4.cell(row=a, column=5, value=stat_birth)
        mzt4.cell(row=a, column=6, value=politics_statused)
        mzt4.cell(row=a, column=7, value=units)
        mzt4.cell(row=a, column=8, value=positions)
        mzt4.cell(row=a, column=9, value=others_type)
        mzt4.cell(row=a, column=10, value=naures)
        mzt4.cell(row=a, column=11, value=exchanges)
        mzt5.cell(row=a, column=1, value=card)
        mzt5.cell(row=a, column=2, value=name)
        mzt5.cell(row=a, column=3, value=card)
        mzt5.cell(row=a, column=4, value=card)
        mzt5.cell(row=a, column=5, value=card)
        mzt5.cell(row=a, column=6, value=card)
        mzt5.cell(row=a, column=7, value=card)
        mzt5.cell(row=a, column=8, value=card)
        mzt5.cell(row=a, column=9, value=card)
        mzt5.cell(row=a, column=10, value=card)
        mzt5.cell(row=a, column=11, value=card)
        mzt5.cell(row=a, column=12, value=card)
        mzt5.cell(row=a, column=13, value=card)


        if a == mag:
            break


def begin():
    while True:
        message()
        print('---------执行完成---------')
        print('是否继续:')
        res = input('请输入y/n：')
        if res == 'y':
            continue
        else:
            print("谢谢使用")
            break


if __name__ == '__main__':
    begin()